import { defineStore } from 'pinia';
import { ref } from 'vue';
import { getCurrentUser } from '@/network/user';

export const useLoginUserStore = defineStore('loginUser', () => {
  const loginUser = ref({
    userName: ""
  });

  const getLoginUser = async () => {
    const res = await getCurrentUser();
    if (res.code === 200 && res.data) {
      loginUser.value = res.data;
    }
  };

  const setLoginUser = (newLoginUser) => {
    loginUser.value = newLoginUser;
  };

  return { loginUser, getLoginUser, setLoginUser };
})